package com.yawn.demomybatis.controller;

import com.yawn.demomybatis.dao.PersonDao;
import com.yawn.demomybatis.dao.PersonDao2;
import com.yawn.demomybatis.dao.PersonDao3;
import com.yawn.demomybatis.entity.Person;
import com.yawn.demomybatis.entity.School;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PersonController {

    @Autowired
    private PersonDao personDao;
    @Autowired
    private PersonDao2 personDao2;
    @Autowired
    private PersonDao3 personDao3;

    @GetMapping("/get")
    public Person get(String id) {
        return personDao.get(id);
    }
    @GetMapping("/list")
    public List<Person> list() {
        return personDao.list();
    }

    @PostMapping("/add")
    public int add(@RequestBody Person person) {
        return personDao.add(person);
    }

    @GetMapping("/get2")
    public Person get2(String id) {
        return personDao2.get(id);
    }
    @GetMapping("/list2")
    public List<Person> list2() {
        return personDao2.list();
    }

    @GetMapping("/get3")
    public Person get3(String id) {
        Person person = personDao3.get(id);
        School school = person.getSchool();
        System.out.println(school);
        return person;
    }
    @GetMapping("/list3")
    public List<Person> list3() {
        return personDao3.list();
    }
}
